<?php
session_start();

function doLogin()
{
	if(!empty($_POST['username']) && !empty($_POST['password'])){
		$userName = $_POST['username'];
		$pass = $_POST['password'];
		$link = mysql_connect('localhost', $userName, $pass);

		if(!$link) {
			echo "fail";		
		}else{		
			$_SESSION['username'] = $userName;
			$_SESSION['password'] = $pass;
			if(!empty($_SESSION['username'])){
				echo $_SESSION['username'] ;
			}else{
				echo "fail";
			}
		}
	}else{
		echo "fail";
	}
}

if(session_id() != ''){
	if(!empty($_SESSION['username'])){
		echo $_SESSION['username'];
	}else{
		doLogin();
	}
}else{
	doLogin();
}
	
?>
